package www.openteam.com.model.realtime;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.List;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.ProducePro;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2017/1/5.
 */

public class ProduceScheduleModel   extends BaseModel {


        private boolean isQuery= false;

        public  boolean queryProd(@NonNull String rdsno,
                                  @NonNull String custid,
                                  @NonNull String code,
                                  long startDate,
                                  long endDate,
                                  String stype, String moreCom,
                                  int userId,String jMark,
                                  @NonNull int PageSize,@NonNull final
                                  ProduceScheduleOnListener produceScheduleOnListener){

                httpApiService.queryProd(rdsno, custid, code, startDate, endDate, stype,moreCom,userId,jMark,PageSize)
                        .compose(new CommonTransformer<ProducePro>())
                        .subscribe(new CommonSubscriber<ProducePro>(OTApplication.getmContext()) {
                            @Override
                            public void onNext(ProducePro producePro) {
//                                producePro.getData().get(0).setCustName("深圳开盟");
                                isQuery=true;
                                produceScheduleOnListener.queryPSSuccess(producePro.getData());
                            }

                            @Override
                            protected void onError(ApiException e) {
                                super.onError(e);
                                isQuery =false;
                                produceScheduleOnListener.queryPSFail(e.getMessage());
                            }
                        });
            return  isQuery;
        }




        public interface  ProduceScheduleOnListener{

                void queryPSSuccess(List<ProducePro.DataEntity> data);

                void queryPSFail(String failMsg);

        }
}
